package com.sl.demo.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import com.sl.demo.entity.User;

public interface UserDao extends JpaRepository<User, Integer> {

	//jpa原生的
	
	//按照JPA规则定义的方法
	User findByName(String name);
	
	@Query(value="select * from users where name = ?1 and age = ?2",nativeQuery=true)
	List<User> find(String name,Integer age);
	
	@Query(value="select * from users where id in ?1",nativeQuery=true)
	List<User> findUserByIds(List<Integer> ids);

	//JPQL
	@Transactional
	@Modifying
	@Query(value="delete from users where name in ?1",nativeQuery=true)
	void deleteByNames(List<String> names);
	
	@Transactional
	@Modifying
	@Query(value="delete from users where name=:name",nativeQuery=true)
	void deleteByName(@Param(value="name") String  names);
	
}
